package util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import entity.ImageItem;

/*
 * loads a bunch of items to db from a file: initial_load
 * initial_load is a comma-delimited file, with pipe-delimited sub-fields (ex. tag array attribute)
 * each row represents an Item object
 */
public class BatchLoader {
	
	public BatchLoader() {
	}

	public BatchLoader(String _filename) {
		BufferedReader br = null;
		try {
			br = new BufferedReader(new FileReader(_filename));
			String line = null;
			String[] itemData = null;
			while ((line = br.readLine()) != null) {
				itemData = line.split(",");
				ImageItem anItem = new ImageItem(itemData[0],itemData[1]);
				anItem.save();
	    	}			
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}   
	}
}